const tree = [
  {
    id: 1,
    name: 'Node 1',
    children: [
      {
        id: 2,
        name: 'Node 1.1',
        children: [
          {
            id: 4,
            name: 'Node 1.1.1',
            children: []
          },
          {
            id: 5,
            name: 'Node 1.1.2',
            children: []
          }
        ]
      },
      {
        id: 3,
        name: 'Node 1.2',
        children: []
      }
    ]
  },
  {
    id: 6,
    name: 'Node 2',
    children: [
      {
        id: 7,
        name: 'Node 2.1',
        children: []
      }
    ]
  }
];

function flatTreeNodes (tree) {
  let list = []
  function _flatTreeNodes (tree) {
    tree.forEach(item => {
      list.push(item)
      // if (node.children && node.children.length > 0)
      if (Array.isArray(item.children)) {
        _flatTreeNodes(item.children)
      }
      // 删除多余的children属性，因为已经展开为一维数组了
      delete item.children
    });
  }
  _flatTreeNodes(tree)
  return list
}
console.log(flatTreeNodes(tree));
